package archivos;

import java.sql.*;

public class Conexion 
{
    
    Statement stmt;
    Connection con;
    
    
   public Conexion()
   {
   }
    
    public void conectar()
	{
        
       String driver = "org.postgresql.Driver";
       String connectString = "jdbc:postgresql://localhost:5432/registro";
       String user = "postgres";
       String password = "postgres";

       try
	   {
            Class.forName(driver);
            con = DriverManager.getConnection(connectString,user,password);
            stmt = con.createStatement();
       }

       catch ( Exception e )
	   {
            System.out.println("Error al conectar: "+ e.getMessage());
       }
    }
    
    public void cerrarConexion()
	{
        try
		{
            stmt.close();
            con.close();
        }
        catch(Exception e)
		{
            System.out.println("Error al cerrar la conexion: "+ e.getMessage());
        }
    }
    
    public ResultSet consultar(String consulta)
	{
      ResultSet res = null;  
      try
	   {
            res = stmt.executeQuery(consulta);
            
       }
       catch(Exception e)
	   {
            System.out.println(e);
       }        
       return res; 
    }
}
